package com.cursor.config;

import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.io.File;

@Configuration
public class SQLiteConfig {

    @Bean
    @Primary
    public DataSource dataSource() {
        // 获取当前运行目录
        String currentDir = System.getProperty("user.dir");
        // 构建数据库文件路径 - 修改为db子目录
        String dbPath = currentDir + File.separator + "db" + File.separator + "cursorswitcher.db";
        
        // 确保db目录存在
        File dbDir = new File(currentDir + File.separator + "db");
        if (!dbDir.exists()) {
            dbDir.mkdir();
        }
        
        System.out.println("SQLite数据库文件路径: " + dbPath);
        
        return DataSourceBuilder.create()
                .driverClassName("org.sqlite.JDBC")
                .url("jdbc:sqlite:" + dbPath)
                .build();
    }
} 